<?php 
## include required files
/*******************************/
require_once '../model/admindetails.php';
/*******************************/
## Create Objects
/*******************************/
$adminObj = new Model_AdminDetails();
/*******************************/
if(isset($_POST['changepassword_btn'])) {
	## apply PHP validation for required filed
	if(trim($_POST['cpassword']) != '' && trim($_POST['npassword']) != '') {
			$userId=$_SESSION["admin_id"];
			$adminArr=$adminObj->checkpassword($userId,$_POST['cpassword']);
			if(count($adminArr) >0){
			extract($_POST);
			$userArray = array();
			$userArray['password']  = return_post_value(md5($npassword));
			$adminObj->editUserValueById($userArray,$userId);
			$_SESSION['msg'] = "<div class='success_msg'><span>You have changed Password successfully. </span></div>";
			header('location:'.SITE_URL.'/admin/home.php');
			exit;
		} else { // checking password is valid
			$_SESSION['msg'] = "<div class='error_msg'><span>You have enter current password wrong.</span></div>";
		}
	} else {// php validation else
		$_SESSION['msg'] = "<div class='error_msg'><span>Please enter current and new password.</span></div>";
	}
	// main if closed
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Unset all the objects created which are on this page
unset($adminObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'settings/changepassword.tpl');
unset($smarty);
?>